package br.ucb.ucblive.managedbean;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;


import br.ucb.ucblive.HIB.DisciplinaHIB;
import br.ucb.ucblive.HIB.ProfessorHIB;
import br.ucb.ucblive.beans.Disciplina;

import br.ucb.ucblive.beans.Moderador;
import br.ucb.ucblive.beans.Professor;
import br.ucb.ucblive.beans.Usuario;

@ManagedBean (name="professorManagedBean")
@SessionScoped
public class ProfessorManagedBean {
	private Professor professor;
	private List<Professor> professores;
	private ProfessorHIB professorhib;
	private List<Disciplina> disciplinaLogado;
	private String query;
	
	public ProfessorManagedBean(){
		setProfessor(new Professor());
		setProfessores(new ArrayList<Professor>());
		setProfessorhib(new ProfessorHIB());
		setQuery(new String());
	}

	public List<Disciplina> getDisciplinaLogado() {
		return disciplinaLogado;
	}

	public void setDisciplinaLogado(List<Disciplina> disciplinaLogado) {
		this.disciplinaLogado = disciplinaLogado;
	}

	public Professor getProfessor() {
		return professor;
	}

	public void setProfessor(Professor professor) {
		this.professor = professor;
	}

	public List<Professor> getProfessores() {
		return professores;
	}

	public void setProfessores(List<Professor> professores) {
		this.professores = professores;
	}
	
	public ProfessorHIB getProfessorhib() {
		return professorhib;
	}

	public void setProfessorhib(ProfessorHIB professorhib) {
		this.professorhib = professorhib;
	}
	
	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	public void insere(Usuario usuario) {
		getProfessor().setUsuario(usuario);
		getProfessores().add(getProfessor());
		professorhib.salvar(professor);
		setProfessor(new Professor());
	}
	public void populaDisciplinaProfessor(Usuario usuario)throws SQLException{
		DisciplinaHIB disciplinaHib = new DisciplinaHIB();
		disciplinaLogado =disciplinaHib.listarDisciplinasByUsuario(usuario);
	}
	
	public String listarProfessor(){
		setProfessores(new ArrayList<Professor>());
		List<Professor> users = new ArrayList<Professor>();
		
		for (Professor p : professorhib.listarOrdemCrescente()){
			if(p.getNome().toUpperCase().contains(query.toUpperCase()))
				users.add(p);
		}
		professores.addAll(users);
		setQuery(new String());
		return "/adm/professorList?faces-redirect=true";
	}
	
	

}
